package com.chujiekeji.test.adapter;

import android.content.Context;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.chujiekeji.test.R;
import com.chujiekeji.test.bean.FriendCircle;
import com.chujiekeji.test.widget.AvatarView;

import java.util.Random;

import butterknife.BindView;
import butterknife.ButterKnife;

public class FriendCircleAdapter extends BaseRecyclerAdapter<FriendCircle> {
    public FriendCircleAdapter(Context context, int mode) {
        super(context, mode);
    }

    @Override
    protected RecyclerView.ViewHolder onCreateDefaultViewHolder(ViewGroup parent, int type) {
        return new ViewHolder(LayoutInflater.from(mContext).inflate(R.layout.friend_item, parent, false));
    }

    @Override
    protected void onBindDefaultViewHolder(RecyclerView.ViewHolder holder, FriendCircle item, int position) {
        FriendCircleAdapter.ViewHolder viewHolder = (FriendCircleAdapter.ViewHolder)holder;
        getRandomLength();
        viewHolder.image2.setVisibility(View.GONE);
        viewHolder.image3.setVisibility(View.GONE);
        if (getRandomLength() == 1) {
            viewHolder.image1.setVisibility(View.VISIBLE);
        } else if (getRandomLength() == 2) {
            viewHolder.image1.setVisibility(View.VISIBLE);
            viewHolder.image2.setVisibility(View.VISIBLE);
        } else if (getRandomLength() == 3) {
            viewHolder.image1.setVisibility(View.VISIBLE);
            viewHolder.image2.setVisibility(View.VISIBLE);
            viewHolder.image3.setVisibility(View.VISIBLE);
        }
    }
    public static class ViewHolder extends RecyclerView.ViewHolder {
        CardView cardView;
        @BindView(R.id.friend_image)
        ImageView image1;
        @BindView(R.id.friend_imag)
        ImageView image2;
        @BindView(R.id.friend_ima)
        ImageView image3;
        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
            cardView = (CardView) itemView;
        }
    }

    /**
     * 和Activity通信的接口
     */
    public interface onSwipeListener {
        void onDel(int pos);

        void onTop(int pos);
    }

    private onSwipeListener mOnSwipeListener;

    public onSwipeListener getOnDelListener() {
        return mOnSwipeListener;
    }

    public void setOnDelListener(onSwipeListener mOnDelListener) {
        this.mOnSwipeListener = mOnDelListener;
    }

    private int getRandomLength() {
        Random random = new Random();
        int length = random.nextInt(3) + 1;
        return length;
    }
}
